package com.wang.exception_hw2;

public class CheckingAccount extends Account{
    private double overdraftProtection;

    public CheckingAccount(double balance, double overdraftProtection) {
        super(balance);
        this.overdraftProtection = overdraftProtection;
    }

    @Override
    public void withdraw(double amount) throws OverdraftException {
        if (getBalance() + overdraftProtection < amount){
            throw new OverdraftException("余额不足！",amount - getBalance() -overdraftProtection);
        }
        if (getBalance() < amount){
            overdraftProtection -= amount - getBalance();
            super.withdraw(getBalance());
        } else {
            super.withdraw(amount);
        }
    }
}
